<template>
  <div class="login">
    <div class="login-content">
      <div class="login-header">登录</div>
      <el-form label-position="right" label-width="60px" :model="user">
        <el-form-item label="用户名">
          <el-input v-model="user.userName"></el-input>
        </el-form-item>
        <el-form-item label="密　码">
          <el-input type="password" v-model="user.password"></el-input>
        </el-form-item>
      </el-form>
      <div class="login-footer">
        <button type="button" @click="login()" class="button">登录</button>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        user: {
          userName: '',
          password: ''
        }
      }
    },
    mounted() {
    },
    methods: {
      login() {
        let _self = this
        if (_self.user.userName === '' || _self.user.password === '') {
          _self.$message({
            type: 'info',
            message: '帐号和密码不能为空'
          })
          return
        }
        _self.$ajax.post('/weChat/login', _self.user).then(function (response) {
          console.info(response)
          if (response.data.code !== 1) {
            _self.$message({
              type: 'info',
              message: response.data.msg
            })
          } else {
            _self.$store.commit('SET_USER', response.data.user)
            if (_self.$route.query.redirect) {
              _self.$router.push({
                path: _self.$route.query.redirect
              })
            } else {
              _self.$router.push({
                path: '/'
              })
            }
          }
        }).catch(function (error) {
          console.log(error)
        })
      }
    },
    watch: {},
    created() {
    }
  }
</script>

<style lang="less" scoped>
  @import "login";
</style>
